import { getUUID } from "@/utils/uuid_token.js";
import { reqgetDetailList, reqAddorUpdataShopCartList } from "@/api/index.js";
const state = {
  getDetailList: {},
  //随机生成字符串
  uuid_token: getUUID(),
};
const mutations = {
  GETDETAILLIST(state, getDetailList) {
    state.getDetailList = getDetailList;
  },
};
const actions = {
  async getDetailList({ commit }, skuId) {
    let result = await reqgetDetailList(skuId);

    if (result.code == 200) {
      commit("GETDETAILLIST", result.data);
    }
  },
  async getAddorUpdataList({ commit }, { skuId, skuNum }) {
    let result = await reqAddorUpdataShopCartList(skuId, skuNum);
    if (result.code == 200) {
      return "ok";
    } else {
      return Promise.reject(new Error("faile"));
    }
  },
};
const getters = {
  categoryView(state) {
    return state.getDetailList.categoryView || {};
  },
  skuInfo(state) {
    return state.getDetailList.skuInfo || {};
  },
  spuSaleAttrList(state) {
    return state.getDetailList.spuSaleAttrList || [];
  },
};

export default {
  state,
  mutations,
  actions,
  getters,
};
